#!/bin/bash
# 检查 build-essential 包是否未安装，如果是，则安装它
if ! dpkg -s build-essential > /dev/null 2>&1; then
    apt-get update -y
    apt-get install -y build-essential
fi
#检查 cmake 是否已安装
if ! command -v cmake >/dev/null 2>&1; then
    echo "cmake 未安装正在尝试安装"
    apt-get update -y
    apt-get install -y cmake
fi
# 获取当前脚本的绝对路径
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd $(dirname $SCRIPT_PATH)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    exit 1
fi
rm -rf /opt/module/stamp/ffmpeg/n8.1-dev/ffmpeg_n8.1-dev-configure*
#rm -rf /opt/external/project/mysql/client/mysql-9.4.0/src/mysql_client_build_mysql-9.4.0-stamp/mysql_client_build_mysql-9.4.0-download*
cd ../..
CMAKEWORKDIR=$(pwd)
# 生成临时文件
#build_DIR="/tmp/$(date +"%Y-%m-%d-%H-%M-%S")"
BUILD_DIR="/tmp/build/module_manager/debug"
#删除 临时文件
rm -rf $BUILD_DIR
# 生成构建目录-DBUILD_SHARED_LIBS=OFF \  # 禁用共享库
cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=debug \
-D WITH_FFMPEG=ON \
-D CMAKE_PREFIX_PATH=/opt/module/prefix \
-D MODULE_PREFIX=/opt/module/ \
-S $CMAKEWORKDIR -B $BUILD_DIR
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "配置失败"
    exit 1
fi
#cmake --build $BUILD_DIR -j$(nproc)
cmake --build $BUILD_DIR --target ffmpeg_n8.1-dev-configure
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "编译失败"
    exit 1
fi
# 安装
#cmake --install $BUILD_DIR









